// http服务
const http = require('http');
const server = http.createServer();
// 为服务器实例绑定request事件，即可监听客户端发送过来的网络请求:
server.on('request', (req,res)=>{
    // const str = `您请求的url地址是${req.url}，请求的 method类型是${req.method}`;
    const url = req.url;
    let content = '<h1>404 Not found!</h1>' //2．设置默认的内容为404 Not found
    if(url === '/' || url === '/index.html') {
        content = '<h1>首页</h1>'
    }
    if(url === '/about.html') {
        content = '<h1>关于页面</h1>'
    }
    res.setHeader('Content-Type','text/html;charset=utf-8');
    res.end(content);
})
// 调用服务器实例的.listen()方法，即可启动当前的web 服务器实例:
server.listen(8082, ()=>{
    console.log('http server running at http://127.0.0.1:8082');
})